from QQLoginTool.QQtool import OAuthQQ
from django.http import JsonResponse
from django.shortcuts import render

# Create your views here.
from django.views import View

from meiduo import settings


class QQAuthURLView(View):
    def get(self,request):
        # next表示从哪个页面进入到的登录页面，将来登录成功后，就自动回到那个页面
        next=request.GET.get('next')
        # 获取QQ登录页面网址
        oauth = OAuthQQ(client_id=settings.QQ_CLIENT_ID,
                        client_secret=settings.QQ_CLIENT_SECRET,
                        redirect_uri=settings.QQ_REDIRECT_URI,
                        state=next)
        login_url = oauth.get_qq_url()
        return JsonResponse({'code': 0,'errmsg': 'OK','login_url':login_url})
